package com.jackeysun.app_common

import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.multidex.MultiDexApplication
import com.jackeysun.common.ActivityManager.popActivity
import com.jackeysun.common.ActivityManager.pushActivity
import com.jackeysun.util.Application.mApplication

/**
 *   Created by sunxunchao on 2021/11/24.
 */
class APP : MultiDexApplication(){

    companion object{
        lateinit var app: APP
    }

    override fun onCreate() {
        super.onCreate()
        app = this
        mApplication = this
        registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
    }

    private val activityLifecycleCallbacks: ActivityLifecycleCallbacks =
        object : ActivityLifecycleCallbacks {
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { activity.pushActivity() }
            override fun onActivityStarted(activity: Activity) {}
            override fun onActivityResumed(activity: Activity) {}
            override fun onActivityPaused(activity: Activity) {}
            override fun onActivityStopped(activity: Activity) {}
            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
            override fun onActivityDestroyed(activity: Activity) { activity.popActivity() }
        }
}